//
//  UIButton+Extension.swift
//  HMWeibo
//
//  Created by wulei on 15/12/6.
//  Copyright © 2015年 wulei. All rights reserved.
//

import UIKit

extension UIButton {
    
   convenience init(imageName: String, backImageName: String?) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
    
    if let backImageName = backImageName {
        
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
    }
        sizeToFit()
    }
    
    convenience init(title: String, color: UIColor, backimageName: String) {
        self.init()

        setTitle(title, forState: UIControlState.Normal);
        setTitleColor(color, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backimageName), forState: UIControlState.Normal)
        sizeToFit()
    }
    
    convenience init(title: String, fontSize: CGFloat, color: UIColor, imageName: String?, backColor: UIColor? = nil) {
        self.init()
        
        setTitle(title, forState: UIControlState.Normal);
        setTitleColor(color, forState: UIControlState.Normal)
        if let imageName = imageName {
            
            setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        }
        
        backgroundColor = backColor
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        sizeToFit()
    }
    
    
    
}